package com.project.gjbus.controller;

import com.project.gjbus.dto.ParamDto;
import com.project.gjbus.entity.*;
import com.project.gjbus.service.*;
import com.project.gjbus.util.RestResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/gjbus/api/")
public class GjbusController {

    @Resource
    CheliangService cheliangService;
    @Resource
    JinchuzhanService jinchuzhanService;
    @Resource
    LudanService ludanService;
    @Resource
    RfidService rfidService;
    @Resource
    ShikeService shikeService;
    @Resource
    SijiService sijiService;
    @Resource
    XianluService xianluService;
    @Resource
    YouhaoService youhaoService;
    @Resource
    ZhanjiService zhanjiService;
    @Resource
    DailyService dailyService;

    @PostMapping("cheliang/count")
    public RestResult cheliangCount(@RequestBody ParamDto paramDto) {
        Integer count = cheliangService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("cheliang/readbase/count")
    public RestResult cheliangReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = cheliangService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("cheliang/save")
    public RestResult cheliangSave(@RequestBody ParamDto paramDto) {
        List<Cheliang> list = cheliangService.getList(paramDto);
        if (list != null && list.size() > 0) {
            cheliangService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("jinchuzhan/count")
    public RestResult jinchuzhanCount(@RequestBody ParamDto paramDto) {
        Integer count = jinchuzhanService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("jinchuzhan/flag/count")
    public RestResult jinchuzhanFlagCount() {
        Integer count = jinchuzhanService.getCountByFlag();
        return RestResult.ok(count);
    }

    @PostMapping("jinchuzhan/readbase/count")
    public RestResult jinchuzhanReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = jinchuzhanService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("jinchuzhan/save")
    public RestResult jinchuzhanSave(@RequestBody ParamDto paramDto) {
        List<Jinchuzhan> list = jinchuzhanService.getList(paramDto);
        if (list != null && list.size() > 0) {
            jinchuzhanService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("jinchuzhan/flag/save")
    public RestResult jinchuzhanFlagSave(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        List<Jinchuzhan> list = jinchuzhanService.getListByFlag(paramDto);
        if (list != null && list.size() > 0) {
            jinchuzhanService.saveList(list);
            jinchuzhanService.deleteById(list.get(list.size() - 1).getId());
        }
        return RestResult.ok();
    }

    @PostMapping("ludan/count")
    public RestResult ludanCount(@RequestBody ParamDto paramDto) {
        Integer count = ludanService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("ludan/readbase/count")
    public RestResult ludanReadbaseCount(@RequestBody ParamDto paramDto) {
        Integer count = ludanService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("ludan/save")
    public RestResult ludanSave(@RequestBody ParamDto paramDto) {
        List<Ludan> list = ludanService.getList(paramDto);
        if (list != null && list.size() > 0) {
            ludanService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("rfid/count")
    public RestResult rfidCount(@RequestBody ParamDto paramDto) {
        Integer count = rfidService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("rfid/readbase/count")
    public RestResult rfidReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = rfidService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("rfid/save")
    public RestResult rfidSave(@RequestBody ParamDto paramDto) {
        List<Rfid> list = rfidService.getList(paramDto);
        if (list != null && list.size() > 0) {
            rfidService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("shike/count")
    public RestResult shikeCount(@RequestBody ParamDto paramDto) {
        Integer count = shikeService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("shike/readbase/count")
    public RestResult shikeReadbaseCount(@RequestBody ParamDto paramDto) {
        Integer count = shikeService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("shike/save")
    public RestResult shikeSave(@RequestBody ParamDto paramDto) {
        List<Shike> list = shikeService.getList(paramDto);
        shikeService.saveList(list);
        return RestResult.ok();
    }

    @PostMapping("siji/count")
    public RestResult sijiCount(@RequestBody ParamDto paramDto) {
        Integer count = sijiService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("siji/readbase/count")
    public RestResult sijiReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = sijiService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("siji/save")
    public RestResult sijiSave(@RequestBody ParamDto paramDto) {
        List<Siji> list = sijiService.getList(paramDto);
        if (list != null && list.size() > 0) {
            sijiService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("xianlu/count")
    public RestResult xianluCount(@RequestBody ParamDto paramDto) {
        Integer count = xianluService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("xianlu/readbase/count")
    public RestResult xianluReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = xianluService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("xianlu/save")
    public RestResult xianluSave(@RequestBody ParamDto paramDto) {
        List<Xianlu> list = xianluService.getList(paramDto);
        if (list != null && list.size() > 0) {
            xianluService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("youhao/count")
    public RestResult youhaoCount(@RequestBody ParamDto paramDto) {
        Integer count = youhaoService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("youhao/readbase/count")
    public RestResult youhaoReadbaseCount(@RequestBody ParamDto paramDto) {
        Integer count = youhaoService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("youhao/save")
    public RestResult youhaoSave(@RequestBody ParamDto paramDto) {
        List<Youhao> list = youhaoService.getList(paramDto);
        if (list != null && list.size() > 0) {
            youhaoService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("zhanji/count")
    public RestResult zhanjiCount(@RequestBody ParamDto paramDto) {
        Integer count = zhanjiService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("zhanji/readbase/count")
    public RestResult zhanjiReadbaseCount(@RequestBody ParamDto paramDto) {
        paramDto.setStartDate(paramDto.getStartDate() + " 00:00:00");
        paramDto.setEndDate(paramDto.getEndDate() + " 23:59:59");
        Integer count = zhanjiService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("zhanji/save")
    public RestResult zhanjiSave(@RequestBody ParamDto paramDto) {
        List<Zhanji> list = zhanjiService.getList(paramDto);
        if (list != null && list.size() > 0) {
            zhanjiService.saveList(list);
        }
        return RestResult.ok();
    }

    @PostMapping("daily/count")
    public RestResult dailyCount(@RequestBody ParamDto paramDto) {
        Integer count = dailyService.getCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("daily/readbase/count")
    public RestResult dailyReadbaseCount(@RequestBody ParamDto paramDto) {
        Integer count = dailyService.getReadBaseCount(paramDto);
        return RestResult.ok(count);
    }

    @PostMapping("daily/save")
    public RestResult dailySave(@RequestBody ParamDto paramDto) {
        List<Daily> list = dailyService.getList(paramDto);
        if (list != null && list.size() > 0) {
            dailyService.saveList(list);
        }
        return RestResult.ok();
    }
}
